export default arr => {
  const p = []
  const c = []

  arr.data.filter(e => {
    if (e.commercialCode.length === 2) {
      p.push(e)
    } else {
      c.push(e)
    }
  })

  function generateType(p, c) {
    p.map(parent => {
      c.map(children => {
        if (children.commercialCode.slice(0, 2) === parent.commercialCode) {
          if (parent.children) {
            parent.children.push(children)
          } else {
            parent.children = [children]
          }
        }
      })
    })
  }
  generateType(p, c)
  const all = {
    commercialCode: '全部分类',
    commercialName: '全部分类',
    id: 123456789
  }
  p.unshift(all)
  return p
}
